<?php
namespace modules\post\action\submit\posts;

use library\AjaxAction;
use idea\ap\Ap;
use idea\util\Upload;
use helper\Util;

/**
 * EditAction class file
 * Ajax方式更新文档
 * @author 宋欢 <iphper@yeah.net>
 * @version $Id: EditAction.php 1 2013-02-08 00:48:06Z huan.song $
 * @package modules.post.action.submit.posts;
 * @since 1.0
 */
class EditAction extends AjaxAction
{
	/**
	 * (non-PHPdoc)
	 * @see idea\mvc\interfaces.Action::run()
	 */
	public function run()
	{
		$do = Ap::getRequest()->getString('do');
		if ($do === 'upload') {
			$upload = new Upload(DIR_DATA . '/little_picture', Upload::NAMERULE_TIMESTAMP_RAND);
			$data = array();
			try {
				$savePath = str_replace(DIR_ROOT, '', $upload->save($_FILES['little_picture_file']));
				$data['save_path'] = str_replace('\\', '/', $savePath);
			}
			catch (\Exception $e) {
				$this->errNo = $e->getCode();
				$this->errMsg = $e->getMessage();
			}
			
			sleep(1);
			$this->display($data);
		}
		else {
			$id = Ap::getRequest()->getTrim('id');
			$status = Ap::getRequest()->getTrim('status');
			$ret = Util::getService('Posts', 'post')->editStatus($id, $status);
			$this->display($ret);
		}
	}
}
